from __future__ import annotations

from dataclasses import dataclass
from math import pi


@dataclass
class ColumnBuckling:
    slenderness: float
    euler_capacity_kN: float
    ok: bool
    note: str


def check_euler_buckling(
    elastic_modulus_kN_mm2: float,
    moment_of_inertia_mm4: float,
    effective_length_mm: float,
    axial_design_kN: float,
) -> ColumnBuckling:
    """钢柱欧拉屈曲承载力验算（弹性阶段）。"""

    slenderness = effective_length_mm / max(1e-6, (moment_of_inertia_mm4 ** 0.5))
    Pcr_N = (pi ** 2) * elastic_modulus_kN_mm2 * 1e3 * moment_of_inertia_mm4 / max(1e-6, effective_length_mm ** 2)
    Pcr_kN = Pcr_N / 1e3
    ok = axial_design_kN <= 0.6 * Pcr_kN
    return ColumnBuckling(slenderness=slenderness, euler_capacity_kN=Pcr_kN, ok=ok, note="按0.6Pcr限值")


